package org.metasketch.graphics;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

@XStreamAlias("point")
public class Point {

	@XStreamAsAttribute
	int x;

	@XStreamAsAttribute
	int y;

	public double getDistance(Point b) {
		double distX = x - b.getX();
		double distY = y - b.getY();

		double bdist = distX * distX + distY * distY;

		if (bdist == 0)
			return 0;

		double dist = Math.sqrt(bdist);

		return dist;
	}

	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public boolean withinRadius(double distance, Point point) {
		double distX = x - point.getX();
		double distY = y - point.getY();

		double bdist = distX * distX + distY * distY;

		if (bdist == 0)
			return true;

		double dist = Math.sqrt(bdist);

		if (dist < distance)
			return true;

		return false;

	}

}
